<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("../conn.php");
$db = new DBC();

$productid = "";
$downloadTimes = "";
$flashcode = "";
$name = "";
$author = "";
$url = "";
$month = "";
$version = "";
$size = "";
$imageURL = "";
$type1 = "";
$type2 = "";
$promotion = 0;
if (isset($_GET['flashid'])) {
    $sql = "SELECT * FROM t_music WHERE productid = " . $_GET['flashid'];
    $flashid = $_GET['flashid'];
    $data = $db->fetchData($sql);
    if (count($data) > 0) {
        $productid = $data[0]['productid'];
        $downloadTimes = $data[0]['downloadtimes'];
        $flashcode = $data[0]['flashcode'];
        $name = $data[0]['name'];
        $author = $data[0]['author'];
        $url = $data[0]['url'];
        $price = $data[0]['price'];
        $goodprice = $data[0]['goodprice'];
        $promotion = $data[0]['promotion'];
        $version = $data[0]['version'];
        $size = $data[0]['size'];
        $imageURL = $data[0]['imageURL'];
        $type1 = $data[0]['type1'];
        $type2 = $data[0]['type2'];
        $month = $data[0]['month'];
        $isModify = 1;
    }
} else {
    $isModify = 0;
    $productid = "";
    $downloadTimes = "";
    $flashcode = "";
    $name = "";
    $author = "";
    $url = "";
    $version = "";
    $size = "";
    $imageURL = "";
    $type1 = "";
    $type2 = "";
    $price = "";
    $goodprice = "";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>乐知家园</title>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #CCCCCC;
            }

            .text{
                height:20px;
            }
            .disable{
                background-color:#CCCCCC;
            }
            -->
        </style>
        <script language="javascript">
            function onSubmitCheck(){
                var flashcode = document.getElementById("flashcode").value;
                var flashname = document.getElementById("flashname").value;
                var type2 = document.getElementsByName("type2[]");
                var version = document.getElementById("version").value;
                var apkurl = document.getElementById("apkurl").value;
                var isok = true;
                var ischecked = false;
                for(var i=0;i<type2.length;i++){
                    if(type2[i].checked==true){
                        ischecked = true;
                        break;
                    }
                }
                if(flashcode==""){
                    alert("\u8bf7输入编码");
                    isok = false;
                }else if(flashname==""){
                    alert("\u8bf7输入名称");
                    isok = false;
                }else if(version==""){
                    alert("\u8bf7输入版本");
                    isok = false;
                }else if(apkurl==""){
                    alert("\u8bf7输入应用地址");
                    isok = false;
                }else if(!ischecked){
                    alert("\u8bf7至少选择一项能力");
                    isok = false;
                }
                if(!isok){
                    event.returnValue = false;
                }
            }
        </script>
        <script type="text/javascript" src="js/jQuery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#age").change(function(){
                    $.get("getPackByAge.php?age=1", function(data){
                        var obj = jQuery.parseJSON(data);
                        $('#packselect').children().remove().end();
                        $("#packselect").append('<option value="-1">\u65e0</option>');
                        for(var i=0;i<obj.length;i++){
                            var option = "<option value="+obj[i].packid+">"+obj[i].packcode+"-"+obj[i].name+"</option>";
                            $("#packselect").append(option);
                        }
                    });
                });
            });
        </script>
    </head>

    <body>
        <br/>
        <form id="form1" name="form1" method="post" action="music.action.php" enctype="multipart/form-data">
            <table width="50%" border="0" align="center" cellpadding="1" cellspacing="1">
                <tr>
                    <td height="30" bgcolor="#666666">编号<input name="flashid" type="hidden" value="<?php echo $flashid; ?>"/><input name="isModify" type="hidden" value="<?php echo $isModify; ?>" /></td>
                    <td bgcolor="#9999FF"><input id="flashcode" name="flashcode" type="text" size="50" class="text" value="<?php echo $flashcode; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">音乐名<input name="name2" type="hidden" size="50" class="disable" value="<?php echo $productid; ?>" disabled="disabled"/></td>
                    <td bgcolor="#9999FF"><input id="name" name="name" type="text" size="50" class="text" value="<?php echo $name; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">作者</td>
                    <td bgcolor="#9999FF"><input id="author" name="author" type="text" size="50" class="text" value="<?php echo $author; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">价格</td>
                    <td bgcolor="#9999FF"><input id="price" name="price" type="text" size="10" class="text" value="<?php echo $price; ?>"/> <font color="red">只能输入数字</font></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">促销价格</td>
                    <td bgcolor="#9999FF"><input id="goodprice" name="goodprice" type="text" size="10" class="text" value="<?php echo $goodprice; ?>"/> <font color="red">只能输入数字</font></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">是否打折</td>
                    <td bgcolor="#9999FF"><input id="promotion" name="promotion" type="checkbox" class="text" <?php if ($promotion == "1") { ?> checked="checked" <?php } ?>/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">类型</td>
                    <td bgcolor="#9999FF"><input name="type1" type="radio" class="text" <?php if (stristr($type1, 'a') || $type1 == "") { ?> checked="checked" <?php } ?> value="a" />恬静&nbsp;
                        <input name="type1" type="radio" class="text" <?php if (stristr($type1, 'b')) { ?> checked="checked" <?php } ?> value="b"/>活泼&nbsp;</td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">图标地址</td>
                    <td bgcolor="#9999FF"><input id="imageurl" name="imageURL" type="text" size="50" class="text" value="<?php echo $imageURL; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">音乐地址</td>
                    <td bgcolor="#9999FF"><input id="apkurl" name="url" type="text" size="50" class="text" value="<?php echo $url; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">第几月</td>
                    <td bgcolor="#9999FF"><input id="month" name="month" type="text" size="10" class="text" value="<?php echo $month; ?>"/> <font color="red">只能输入数字</font></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">&nbsp;</td>
                    <td bgcolor="#9999FF">
                        <input type="submit" name="Submit" value="提交" onclick="onSubmitCheck()" />                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>
<?php

function has($type, $num) {
    if (strpos($type, $num) >= 0) {
        return true;
    }
    return false;
}

include_once '../footer.php';
//} else {
//    header("login.php");
//}
?>
